複製別人code的小技巧


有鑑於最近常常在學習時,翻閱到的網站資料的程式碼前面都有標行數,用手動的消除這些行數很愚蠢,所以我就寫了個小小的c++ code來幫我執行這件事情

// basic file operations
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ifstream readfile;
  readfile.open ("example.txt",ios::in);//想要抄寫的程式碼
  ofstream writefile;
  writefile.open("write.txt",ios::out);//削掉前面行數以後存入的檔案位置
  string line;

  while(getline(readfile,line)){
    for(int i = 0;i < 2;i++){
        line[i] = ' ';

      }
//  line.erase(0, line.find_first_not_of(" "));//?除行首空格
    writefile<< line <<"\n";
  }
  readfile.close();
  writefile.close();
  return 0;
}






你可能感興趣的文章

AWS Solutions Architect - Associate (SAA) 學習計畫與備考心得: Module 7

AWS Solutions Architect - Associate (SAA) 學習計畫與備考心得: Module 7

[筆記] React 隨手記 (環境建置、常用功能說明)

[筆記] React 隨手記 (環境建置、常用功能說明)

[筆記] 網路交換資料方式

[筆記] 網路交換資料方式






留言討論